package com.ask.forMe.langchain4j.service;

import org.springframework.stereotype.Service;

import java.util.regex.Pattern;

@Service
public class PrivacyProtectionService {
    // 敏感信息类型的正则表达式
    private static final Pattern PHONE_PATTERN = Pattern.compile("1[3-9]\\d{9}");
    private static final Pattern ID_CARD_PATTERN = Pattern.compile("[1-9]\\d{5}(19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]");

    public String maskSensitiveInfo(String text) {
        text = PHONE_PATTERN.matcher(text).replaceAll("***********");
        text = ID_CARD_PATTERN.matcher(text).replaceAll("******************");
        return text;
    }

    public boolean containsSensitiveInfo(String text) {
        return PHONE_PATTERN.matcher(text).find() ||
                ID_CARD_PATTERN.matcher(text).find();
    }
}
